package cn.dankal.lequ.domain.download;

import android.os.Environment;
import android.util.Log;

import java.io.File;
import java.io.IOException;



public class FileUtils {


    public static  String getDownloadPath() {
        String downloadPath = "";

        Log.i("down123", "getDownloadPath");

        String state = Environment.getExternalStorageState();
        try {
            //SD卡正常挂载
            if (Environment.MEDIA_MOUNTED.equals(state)) {
                downloadPath = Environment.getExternalStorageDirectory() + "/LeQu/Download/";
                if (new File(downloadPath).mkdirs()) {
                    Log.i("down123", "mkdirs success");
                }
                File file = new File(downloadPath + "testTemp");
                if (file.exists())
                    file.delete();
                if (file.createNewFile()) {
                    return downloadPath;
                } else {
                    downloadPath = Environment.getDataDirectory() + "/LeQu/Download/";
                    new File(downloadPath).mkdirs();
                    return downloadPath;
                }
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
        return Environment.getDataDirectory().toString();
    }
}
